package com.nintendo.bubblechat.controller;

import com.nintendo.bubblechat.entity.pojo.ChatMsg;
import com.nintendo.bubblechat.entity.pojo.ChatSnapshot;
import com.nintendo.bubblechat.entity.pojo.FriendsRequest;
import com.nintendo.bubblechat.entity.pojo.GroupChatMsg;
import com.nintendo.bubblechat.entity.vo.GroupChatMsgVo;
import com.nintendo.bubblechat.grace.result.GraceJsonRequest;
import com.nintendo.bubblechat.service.ChatMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chatMsg")
@Slf4j
public class ChatMsgController {
    @Autowired
    private ChatMsgService chatMsgService;
    /**
     * 查找个人未读消息
     * @param friendRequest
     * @return
     */
    @PostMapping("/getUnReadMsg")
    public GraceJsonRequest getUnreadMsg(@RequestBody FriendsRequest friendRequest){
        System.out.println("friendRequest"+friendRequest);
        List<String> chatMsgList =  chatMsgService.findMyUnReadMsg(friendRequest);
        return GraceJsonRequest.ok(chatMsgList);
    }

    /**
     * 获取聊天快照
     * @param acceptUserId
     * @return
     */
    @PostMapping("/getChatSnapshot")
    public GraceJsonRequest getChatSnapshot(@RequestParam("acceptUserId")String acceptUserId){
        List<ChatSnapshot> chatSnapshotList =  chatMsgService.getChatSnapshot(acceptUserId);
        return GraceJsonRequest.ok(chatSnapshotList);
    }

    /**
     * 根据双方id查询聊天记录
     * @param friendRequest
     * @return
     */
    @PostMapping("/findChatHistory")
    public GraceJsonRequest getChatHistory(@RequestBody FriendsRequest friendRequest){
        List<ChatMsg>  chatMsgList =  chatMsgService.findChatHistory(friendRequest);
        return GraceJsonRequest.ok(chatMsgList);
    }
    /**
     * 根据群组id查询群聊消息记录
     */
    @PostMapping("/groupchatlist")
    public GraceJsonRequest groupChatList(@RequestParam("groupId") String  groupId){
        List<GroupChatMsgVo> groupChatMsgVos =  chatMsgService.findGroupChatList(groupId);
        return GraceJsonRequest.ok(groupChatMsgVos);
    }
    /**
     * 获取每个群组的最新的一条消息
     */
    @PostMapping("/groupNewMsg")
    public GraceJsonRequest groupNewMsg(@RequestBody List<String> groupIds){
        List<GroupChatMsgVo> groupChatMsgVos =  chatMsgService.findGroupNewMsg(groupIds);
        return GraceJsonRequest.ok(groupChatMsgVos);
    }
}
